package com.djzhou.gmms.email.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.djzhou.gmms.base.action.BaseAction;
import com.djzhou.gmms.dao.base.impl.BaseDAOImpl;
import com.djzhou.gmms.dao.email.AttachmentDAO;
import com.djzhou.gmms.model.email.TbAttachment;
import com.djzhou.gmms.model.email.TbEmail;

public class AttachmentAction extends BaseAction<TbAttachment>{
	private TbAttachment attachment;
	private List<TbAttachment> list;
	private Integer attachmentId;
	
	@Override
	public String delete() {
		attachmentService.delete(attachmentId);
		msg="删除成功";
		setCurrentPage(currentPage);
		logService.addLog("附件管理",queryUser(),"删除",attachmentId,"TbAttachment",super.queryCompany(),super.queryDepartment());
		return SUCCESS;
	}

	@Override
	public String modify() {
		attachmentService.update(attachment);
		msg="修改成功";
		setCurrentPage(currentPage);
		logService.addLog("附件管理",queryUser(),"编辑",attachment.getAttachmentId(),"TbAttachment",super.queryCompany(),super.queryDepartment());
		return SUCCESS;
	}

	@Override
	public String queryList() {
		if(loadData==null)return SUCCESS;
		HashMap<String, Object> hashMap=new HashMap<String, Object>();
		pageBean=attachmentService.queryPageBean(hashMap, pageSize, currentPage);
		list=pageBean.getList();
		if(currentPage>1){
			if(list==null || list.size()==0){
				setCurrentPage(getCurrentPage()-1);
				pageBean = attachmentService.queryPageBean(hashMap, pageSize, currentPage);
				list=pageBean.getList();
			}
		}
		if(list!=null){
			totalCount=pageBean.getAllRow();
		}else{
			totalCount = 0;
			list = new ArrayList<TbAttachment>();
		}
		totalPage=pageBean.getTotalPage();
		return SUCCESS;
	}

	@Override
	public String save() {
		if(attachment!=null){
			attachmentService.add(attachment);
		}
		setCurrentPage(currentPage);
		logService.addLog("附件管理",queryUser(),"添加",attachment.getAttachmentId(),"TbAttachment",queryCompany(),super.queryDepartment());
		return SUCCESS;
	}

	@Override
	public String toAdd() {
		return SUCCESS;
	}

	@Override
	public String toEdit() {
		setCurrentPage(currentPage);
		attachment=attachmentService.queryById(attachmentId);
		return SUCCESS;
	}

	public TbAttachment getAttachment() {
		return attachment;
	}

	public void setAttachment(TbAttachment attachment) {
		this.attachment = attachment;
	}

	public List<TbAttachment> getList() {
		return list;
	}

	public void setList(List<TbAttachment> list) {
		this.list = list;
	}

	public Integer getAttachmentId() {
		return attachmentId;
	}

	public void setAttachmentId(Integer attachmentId) {
		this.attachmentId = attachmentId;
	}
	
}
